<template>
  <div class="aboutUs" id="aboutUs">
    <div class="aboutUs-banner">
      <img
        src="../../assets/images/aboutus_banner.png"
        id="aboutUs-banner"
        alt=""
      />
    </div>
    <div class="aboutUs-content com-width">
      <div class="about-navbar" id="navbar-wrap">
        <a
          href="#jieshao"
          :class="activeIndex === 'jieshao' ? 'a-active' : ''"
          @click="checkContent('jieshao')"
          >企业介绍</a
        >
        <a
          href="#zhaoxian"
          :class="activeIndex === 'zhaoxian' ? 'a-active' : ''"
          @click="checkContent('zhaoxian')"
          >招贤纳士</a
        >
        <a
          href="#guanyu"
          :class="activeIndex === 'guanyu' ? 'a-active' : ''"
          @click="checkContent('guanyu')"
          >联系我们</a
        >
      </div>
      <div class="about-content-right" id="content-wrap">
        <div class="box" id="jieshao">
          <page-company></page-company>
        </div>
        <div class="box" id="zhaoxian">
          <page-pap></page-pap>
        </div>
        <div class="box" id="guanyu">
          <page-us></page-us>
        </div>
      </div>
    </div>
    <!-- <nav-footer class="navfooter"></nav-footer> -->
  </div>
</template>

<script>
import NavFooter from "../../components/NavFooter.vue";
import pageCompany from "./components/pageCompany.vue";
import pagePap from "./components/pagePap.vue";
import pageUs from "./components/pageUs.vue";

export default {
  components: { pageCompany, pagePap, pageUs, NavFooter },
  data() {
    return {
      activeIndex: "aboutUs",
    };
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {
        this.activeIndex = val.hash;
        this.activeIndex = this.activeIndex.replace("#", "");
        console.log(this.activeIndex);
        this.$nextTick(() => {
          // this.setSliderTop(this.activeIndex);
        });
      },
      // 深度观察监听
      deep: true,
    },
  },
  methods: {
    setSliderTop(activeIndex) {
      if (activeIndex !== "guanyu") {
        var div = document.getElementById(activeIndex);
        let offsetTop = div.offsetTop;
        document.getElementById("navbar-wrap").style.top =
          offsetTop - 10 + "px";
      }
    },
    checkContent(activeIndex) {
      this.activeIndex = activeIndex;
      // this.setSliderTop(this.activeIndex);
    },
  },
  mounted() {
    console.log(this.$route.hash);
    this.activeIndex = this.$route.hash;
    this.activeIndex = this.activeIndex.replace("#", "");
    console.log(this.activeIndex);
    this.$nextTick(() => {
      // this.setSliderTop(this.activeIndex);
    });
  },
};
</script>

<style lang="scss" scoped>
.aboutUs {
  width: 100%;
  .aboutUs-banner {
    width: 100%;
    img {
      min-height: 320px;
      object-fit: cover;
      width: 100%;
    }
  }
  position: relative;
}
.aboutUs-content {
  position: relative;
}
.about-navbar {
  background: #fff;
  position: absolute;
  width: 271px;
  left: 0;
  top: 30px;
  a {
    box-sizing: border-box;
    padding-left: 22px;
    display: block;
    height: 57px;
    line-height: 57px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #666666;
  }
  .a-active {
    border-left: 3px solid #2590f4;
    background: #e7f0f8;
    color: #2590f4;
  }
}

.about-content-right {
  position: absolute;
  padding-bottom: 220px;
  left: 291px;
}
// .navfooter {
//   position: fixed;
//   left: 0;
//   bottom: 0;
// }
</style>
